/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package maxent.mr.tagger;

import edu.stanford.nlp.tagger.maxent.MaxentTagger;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;


/**
 *
 * @author hadoop
 */
public class TaggerMapper extends MapReduceBase
            implements Mapper<LongWritable, Text, LongWritable, Text> {

    // to store path to model
    String modelPath;
    MaxentTagger tagger;

    @Override
    public void configure(JobConf job){

        System.out.println("Configure");
    //            // create path to model
        modelPath = job.get("MaxentTagger.model");

        System.out.println(modelPath);


        try {

            // create new instance of tagger
            tagger = new MaxentTagger(modelPath);
            System.out.println("Loading model completed...");

        } catch (IOException ex) {
            Logger.getLogger(MaxentTaggerMR.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MaxentTaggerMR.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void map(LongWritable key, Text value, OutputCollector<LongWritable, Text> output, Reporter reporter) throws IOException {

        String line = value.toString();
        String taggedLine = tagger.tagString(line);
        output.collect(key, new Text(taggedLine));


    }

}